package com.mmlc.meimei.lichengkongjian.mine;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.easemob.EMConnectionListener;
import com.easemob.EMEventListener;
import com.easemob.EMNotifierEvent;
import com.easemob.chat.EMChat;
import com.easemob.chat.EMChatManager;
import com.easemob.easeui.controller.EaseUI;
import com.easemob.helpdeskdemo.Constant;
import com.mmlc.meimei.lichengkongjian.App;
import com.mmlc.utils.ToastUtils;


/**
 * Created by Administrator on 2016/8/9 0009.
 */
public class ActivityChat extends Activity{
    private EMConnectionListener connectionListener;
    private EMEventListener eventListener;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        startActivity(new Intent(this, com.easemob.helpdeskdemo.ui.LoginActivity.class).putExtra(Constant.MESSAGE_TO_INTENT_EXTRA,
                Constant.MESSAGE_TO_PRE_SALES));
        //设置Appkey 11110000#commmlcmeiqi
      /*  EMChat.getInstance().setAppkey("11110000#commmlcmeiqi");
        initHuanXin();
        setGlobalListener();
        createRandomAccountAndLoginChatServer();*/
    }

    private void createRandomAccountAndLoginChatServer() {

    }

    private void setGlobalListener() {
        // create the global connection listener
        connectionListener = new EMConnectionListener() {
            @Override
            public void onDisconnected(int error) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        ToastUtils.showToast("没有连接成功");
                    }
                });

            }

            @Override
            public void onConnected() {
                // 通知sdk，UI 已经初始化完毕，注册了相应的receiver和listener, 可以接受broadcast了
                EMChat.getInstance().setAppInited();
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        ToastUtils.showToast("链接成功");
                    }
                });

            }
        };
        //注册连接监听
        EMChatManager.getInstance().addConnectionListener(connectionListener);
        registerEventListener();
    }

    private void initHuanXin() {
        if (EaseUI.getInstance().init(App.context)) {
            //在小米手机上当app被kill时使用小米推送进行消息提示，SDK已支持，可选
//            EMChatManager.getInstance().setMipushConfig("2882303761517370134", "5131737040134");
            //设为调试模式，打成正式包时，最好设为false，以免消耗额外的资源
            EMChat.getInstance().setDebugMode(true);
        }
    }

    protected void registerEventListener() {
        eventListener = new EMEventListener() {

            @Override
            public void onEvent(EMNotifierEvent event) {


            }
        };

        EMChatManager.getInstance().registerEventListener(eventListener);
    }
}
